package cn.wolfcode.wolf2w.job;


import cn.wolfcode.wolf2w.redis.service.IStrategyRedisService;
import cn.wolfcode.wolf2w.service.IStrategyService;
import cn.wolfcode.wolf2w.vo.StrategyStatisVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * redis 缓存数据 持久化定时任务
 */
//@Component
public class RedisDataPersistenceJob {

    @Autowired
    private IStrategyRedisService strategyRedisService;

    @Autowired
    private IStrategyService strategyService;


    //注解:定时器
    //cron :  cron 表达式 , 任务计划
    @Scheduled(cron="0/15 * * * * ? ")  //定时任务标签
    public void doWork(){
        //System.out.println("---------"+ System.currentTimeMillis());
        System.out.println("----------初始化---------");
        //从redis 里面获取 所有的vo 对象
        List<StrategyStatisVO> voList = strategyRedisService.queryStatisVOS();

        //将所有的vo对象存到数据库
        for (StrategyStatisVO vo : voList) {
            strategyService.updateStatisVO(vo);
        }


        System.out.println("----------销毁---------");

        //

    }


}
